import fs from "node:fs";
import actionLoader, {ActionLoaderFilterType} from "./action-loader";

function rollupActionLoad(test: RegExp, filter: ActionLoaderFilterType) {
    return {
        name: 'action-load',
        async load(id: string) {
            if (test.test(id)) {
                const code = await actionLoader.load(filter)
                const fileContent = fs.readFileSync(id, 'utf-8')
                return code + '\n' + fileContent
            }
        },
    }
}

export default rollupActionLoad
